package com.wkbb.sports.service.impl;

import com.wkbb.common.base.BaseServiceImpl;
import com.wkbb.common.dto.ResultDTO;
import com.wkbb.sports.feign.BasicFeignService;
import com.wkbb.sports.mapper.DeviceBindMapper;
import com.wkbb.sports.model.*;
import com.wkbb.sports.service.DeviceBindService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class DeviceBindServiceImpl extends BaseServiceImpl<HlifeDeviceBind> implements DeviceBindService {

    @Autowired
    private BasicFeignService basicFeignService;
    @Autowired
    private DeviceBindMapper deviceBindMapper;

    @Autowired
    public void setMapper(DeviceBindMapper mapper) {
        super.setMapper(mapper);
    }

    @Override
    public ResultDTO<HlifeDeviceBind> bindDevice(HlifeDeviceBind info) {
//        HlifeDeviceBind device = deviceBindMapper.getByMac(info.getMacAddress());
//        if (device != null){
//            return ResultDTO.errorResult("无法绑定，该设备已被其他用户绑定");
//        }
        HlifeDeviceBind device = mapper.find(info);
        if (device != null){
//            return ResultDTO.errorResult("已被绑定，请勿重复操作");
            return ResultDTO.errorResult("已绑定，请勿重复操作");
        }
        deviceBindMapper.insert(info);
        return ResultDTO.successResult();
    }
}
